home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / javax / swing / BoundedRangeModel.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  8.2 KB  |  250 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)BoundedRangeModel.java    1.19 98/08/26
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package javax.swing;
  16.  
  17. import javax.swing.event.*;
  18.  
  19.  
  20. /**
  21.  * Defines the data model used by components like Sliders and ProgressBars.
  22.  * Defines four interrelated integer properties: minimum, maximum, extent
  23.  * and value.  These four integers define two nested ranges like this:
  24.  * <pre>
  25.  * minimum <= value <= value+extent <= maximum
  26.  * </pre>
  27.  * The outer range is <code>minimum,maximum</code> and the inner
  28.  * range is <code>value,value+extent</code>.  The inner range
  29.  * must lie within the outer one, i.e. <code>value</code> must be 
  30.  * less than or equal to <code>maximum</code> and <code>value+extent</code>
  31.  * must greater than or equal to <code>minimum</code>, and <code>maximum</code>
  32.  * must be greater than or equal to <code>minimum</code>.
  33.  * There are a few features of this model that one might find a little 
  34.  * surprising.  These quirks exist for the convenience of the
  35.  * Swing BoundedRangeModel clients like like  Slider and ScrollBar.
  36.  * <ul>
  37.  * <li> 
  38.  *   The minimum and maximum set methods "correct" the other 
  39.  *   three properties to acommodate their new value argument.  For 
  40.  *   example setting the model's minimum may change its maximum, value,
  41.  *   and extent properties (in that order), to maintain the constraints
  42.  *   specified above.  
  43.  * 
  44.  * <li>
  45.  *   The value and extent set methods "correct" their argument to 
  46.  *   fit within the limits defined by the other three properties.  
  47.  *   For example if <code>value == maximum</code>, <code>setExtent(10)</code>
  48.  *   would change the extent (back) to zero.
  49.  * 
  50.  * <li> 
  51.  *   The four BoundedRangeModel values are defined as Java Beans properties
  52.  *   however Swing ChangeEvents are used to notify clients of changes rather
  53.  *   than PropertyChangeEvents. This was done to keep the overhead of monitoring
  54.  *   a BoundedRangeModel low. Changes are often reported at MouseDragged rates. 
  55.  * </ul>
  56.  * 
  57.  * @version 1.19 08/26/98
  58.  * @author Hans Muller
  59.  * @see DefaultBoundedRangeModel
  60.  */
  61. public interface BoundedRangeModel
  62. {
  63.     /**
  64.      * Returns the minimum acceptable value.
  65.      *
  66.      * @return the value of the minimum property
  67.      * @see #setMinimum
  68.      */
  69.     int getMinimum();
  70.  
  71.  
  72.     /**
  73.      * Sets the model's minimum to <I>newMinimum</I>.   The 
  74.      * other three properties may be changed as well, to ensure 
  75.      * that:
  76.      * <pre>
  77.      * minimum <= value <= value+extent <= maximum
  78.      * </pre>
  79.      * <p>
  80.      * Notifies any listeners if the model changes.
  81.      *
  82.      * @param newMinimum the model's new minimum
  83.      * @see #getMinimum
  84.      * @see #addChangeListener
  85.      */
  86.     void setMinimum(int newMinimum);
  87.  
  88.  
  89.     /**
  90.      * Returns the model's maximum.  Note that the upper
  91.      * limit on the model's value is (maximum - extent).
  92.      *
  93.      * @return the value of the maximum property.
  94.      * @see #setMaximum
  95.      * @see #setExtent
  96.      */
  97.     int getMaximum();
  98.  
  99.  
  100.     /**
  101.      * Sets the model's maximum to <I>newMaximum</I>. The other 
  102.      * three properties may be changed as well, to ensure that
  103.      * <pre>
  104.      * minimum <= value <= value+extent <= maximum
  105.      * </pre>
  106.      * <p>
  107.      * Notifies any listeners if the model changes.
  108.      *
  109.      * @param newMaximum the model's new maximum
  110.      * @see #getMaximum
  111.      * @see #addChangeListener
  112.      */
  113.     void setMaximum(int newMaximum);
  114.  
  115.  
  116.     /**
  117.      * Returns the model's current value.  Note that the upper
  118.      * limit on the model's value is <code>maximum - extent</code> 
  119.      * and the lower limit is <code>minimum</code>.
  120.      *
  121.      * @return  the model's value
  122.      * @see     #setValue
  123.      */
  124.     int getValue();
  125.  
  126.  
  127.     /**
  128.      * Sets the model's current value to <code>newValue</code> if <code>newValue</code>
  129.      * satisfies the model's constraints. Those constraints are:
  130.      * <pre>
  131.      * minimum <= value <= value+extent <= maximum
  132.      * </pre>
  133.      * Otherwise, if <code>newValue</code> is less than <code>minimum</code> 
  134.      * it's set to <code>minimum</code>, if its greater than 
  135.      * <code>maximum</code> then it's set to <code>maximum</code>, and 
  136.      * if it's greater than <code>value+extent</code> then it's set to 
  137.      * <code>value+extent</code>.
  138.      * <p>
  139.      * When a BoundedRange model is used with a scrollbar the value
  140.      * specifies the origin of the scrollbar knob (aka the "thumb" or
  141.      * "elevator").  The value usually represents the origin of the 
  142.      * visible part of the object being scrolled.
  143.      * <p>
  144.      * Notifies any listeners if the model changes.
  145.      *
  146.      * @param newValue the model's new value
  147.      * @see #getValue
  148.      */
  149.     void setValue(int newValue);
  150.  
  151.  
  152.     /**
  153.      * This attribute indicates that any upcoming changes to the value
  154.      * of the model should be considered a single event. This attribute
  155.      * will be set to true at the start of a series of changes to the value,
  156.      * and will be set to false when the value has finished changing.  Normally
  157.      * this allows a listener to only take action when the final value change in
  158.      * committed, instead of having to do updates for all intermediate values.
  159.      * <p>
  160.      * Sliders and scrollbars use this property when a drag is underway.
  161.      * 
  162.      * @param b true if the upcoming changes to the value property are part of a series
  163.      */
  164.     void setValueIsAdjusting(boolean b);
  165.  
  166.  
  167.     /**
  168.      * Returns true if the current changes to the value property are part 
  169.      * of a series of changes.
  170.      * 
  171.      * @return the valueIsAdjustingProperty.  
  172.      * @see #setValueIsAdjusting
  173.      */
  174.     boolean getValueIsAdjusting();
  175.  
  176.  
  177.     /**
  178.      * Returns the model's extent, the length of the inner range that
  179.      * begins at the model's value.  
  180.      *
  181.      * @return  the value of the model's extent property
  182.      * @see     #setExtent
  183.      * @see     #setValue
  184.      */
  185.     int getExtent();
  186.  
  187.  
  188.     /**
  189.      * Sets the model's extent.  The <I>newExtent</I> is forced to 
  190.      * be greater than or equal to zero and less than or equal to
  191.      * maximum - value.   
  192.      * <p>
  193.      * When a BoundedRange model is used with a scrollbar the extent
  194.      * defines the length of the scrollbar knob (aka the "thumb" or
  195.      * "elevator").  The extent usually represents how much of the 
  196.      * object being scrolled is visible. When used with a slider,
  197.      * the extent determines how much the value can "jump", for
  198.      * example when the user presses PgUp or PgDn.
  199.      * <p>
  200.      * Notifies any listeners if the model changes.
  201.      *
  202.      * @param  newExtent the model's new extent
  203.      * @see #getExtent
  204.      * @see #setValue
  205.      */
  206.     void setExtent(int newExtent);
  207.  
  208.  
  209.  
  210.     /**
  211.      * This method sets all of the model's data with a single method call.
  212.      * The method results in a single change event being generated. This is
  213.      * convenient when you need to adjust all the model data simulaneously and
  214.      * do not want individual change events to occur.
  215.      *
  216.      * @param value  an int giving the current value 
  217.      * @param extent an int giving the amount by which the value can "jump"
  218.      * @param min    an int giving the minimum value
  219.      * @param max    an int giving the maximum value
  220.      * @param isAdjusting a boolean, true if a series of changes are in
  221.      *                    progress
  222.      * 
  223.      * @see #setValue
  224.      * @see #setExtent
  225.      * @see #setMinimum
  226.      * @see #setMaximum
  227.      * @see #setValueIsAdjusting
  228.      */
  229.     void setRangeProperties(int value, int extent, int min, int max, boolean adjusting);
  230.  
  231.  
  232.     /**
  233.      * Adds a ChangeListener to the model's listener list.
  234.      *
  235.      * @param x the ChangeListener to add
  236.      * @see #removeChangeListener
  237.      */
  238.     void addChangeListener(ChangeListener x);
  239.  
  240.  
  241.     /**
  242.      * Removes a ChangeListener from the model's listener list.
  243.      *
  244.      * @param x the ChangeListener to remove
  245.      * @see #addChangeListener
  246.      */
  247.     void removeChangeListener(ChangeListener x);
  248.  
  249. }
  250.